
///
/// shopping_cart_demo01.dart
///

class Item {
  double price = 0.0;
  String name = '';
  Item(String name, double price) {
    this.name = name;
    this.price = price;
  }
}

class ShoppingCart {
  String name = '';
  DateTime date = DateTime.now();
  String code = '';
  List<Item> bookings = [];
  ShoppingCart(String name, String code) {
    this.name = name;
    this.code = code;
    this.date = DateTime.now();
  }
  double price() {
    double sum = 0.0;
    for (var i in bookings) {
      sum += i.price;
    }
    return sum;
  }
  String getInfo() {
    return '购物车信息:' +
        '\n-----------------------------' +
        '\n用户名: ' + name+
        '\n优惠码: ' + code +
        '\n总价: ' + price().toString() +
        '\n日期: ' + date.toString() +
        '\n-----------------------------';
  }
}

void main() {
  ShoppingCart sc = ShoppingCart('张三', '123456');
  sc.bookings = [Item('苹果',10.0), Item('鸭梨',20.0)];
  print(sc.getInfo());
}


